angular.module('starter.services', [])

/**
 * A simple example service that returns some data.
 */
    .factory('LiveService', function($http) {
      // Might use a resource here that returns a JSON array

      // Some fake testing data

      return {
        getBus:function($scope){
          $http({
            method:'POST',
            url:'http://192.168.199.165:3000/lifeService/lifeServiceList',
            data:{
              order:'desc',
              page:1,
              rows:10,
              sort:'createtime'
            }
          }).success(function(data){
            if(data!=null){
              $scope.busList = data.rows;
            }
          });
        },
        showMap: function(coords,lname,city,address) {
          var map = new BMap.Map("allmap");
          var point = new BMap.Point(coords[0], coords[1]);
          map.centerAndZoom(point, 15);
          map.addControl(new BMap.ZoomControl());  //添加地图缩放控件
          var scaleControl=new BMap.ScaleControl();
          map.addControl(scaleControl);//添加比例尺控件

          map.addControl(new BMap.ZoomControl());
          var opts = {
            width : 400,    // 信息窗口宽度
            height: 70,     // 信息窗口高度
            title : lname  // 信息窗口标题
          }
          var infoWindow = new BMap.InfoWindow("点击标注点将进入路线导航", opts);
          map.openInfoWindow(infoWindow,point); //开启信息窗口
          var marker1 = new BMap.Marker(new BMap.Point(coords[0], coords[1]));//创建标注
          map.addOverlay(marker1);//将标注添加到地图中
          map.addEventListener("click", function(){
            var routeSearch=new BMap.RouteSearch();
            var start = {
              latlng:new BMap.Point(116.417854,39.923978),
              name:"起点"
            }
            var end = {
              latlng:new BMap.Point(coords[0], coords[1]),
              name:lname
            }
            var opts = {
              mode:BMAP_MODE_DRIVING,

              region:city
            }
            var ss = new BMap.RouteSearch();
            routeSearch.routeCall(start,end,opts);
          });

        }
      }
    })

.factory('CarInsure', function() {
  // Might use a resource here that returns a JSON array

  // Some fake testing data
  var friends = [
    { id: 0, name: 'Scruff McGruff' },
    { id: 1, name: 'G.I. Joe' },
    { id: 2, name: 'Miss Frizzle' },
    { id: 3, name: 'Ash Ketchum' }
  ];

  return {
    all: function() {
      return friends;
    },
    get: function(friendId) {
      // Simple index lookup
      return friends[friendId];
    }
  }
})

.factory('Clubs', function(){
      var clubs = [
        {id:0, title:'北京车友汇', text:'车友汇车友汇', imgSrc:'img/bg.png', price:860},
        {id:1, title:'北京车友汇', text:'车友汇车友汇', imgSrc:'img/bg.png'}
      ];
      return{
        all: function () {
          return clubs;
        },
        get: function (i) {
          return clubs[i];
        }
      }
    })

.factory('SelfDrive', function () {
      var drives = [
        {id:0, title:'香山自驾游', text:'游香山', imgSrc:'img/bg.png'},
        {id:1, title:'长城自驾游', text:'游长城', imgSrc:'img/bg.png'}
      ]
      return{
        all: function () {
          return drives;
        },
        get: function (i) {
          return drives[i];
        }
      }
    });
